﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

namespace WebApplication.Admins.Controls
{
    public partial class UC_TinTuc : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string searchString = Request.QueryString["Search"] ?? "";
                if (searchString != "")
                    txtTimKiem.Text = searchString;
                Display();

            }
           
        }
        public void Display()
        {
            int howManyPages = 0;

            string page = Request.QueryString["Page"] ?? "1";
            string firstpage = "";
            string pageUrl = "";

            repTinTuc.DataSource = BLL.TinTuc_BLL.Paging(page, out howManyPages);
            repTinTuc.DataBind();
            firstpage = LinkBLL.ToAdminTinTuc();
            pageUrl = LinkBLL.ToAdminTinTuc("{0}");

            pagerTop.Show(int.Parse(page), howManyPages, firstpage, pageUrl, true);
            pagerBottom.Show(int.Parse(page), howManyPages, firstpage, pageUrl, true);
        }

        protected void btnXoa_Click(object sender, EventArgs e)
        {
            string Id = Request.Form["Id"] ?? "";
            if (Id != "")
            {
                foreach (string id in Id.Split(','))
                    BLL.TinTuc_BLL.Xoa(id);
                Display();
            }
        }

        protected void repTinTuc_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "UpdateHienThi")
            {
                string[] ag = e.CommandArgument.ToString().Split('_');
                TinTuc_BLL.CapNhatHienThi(ag[0], !Boolean.Parse(ag[1]));
                Display();
            }

        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {
            string searchString = txtTimKiem.Text.Trim();
            if(searchString.Length>0)

                Response.Redirect(LinkBLL.ToSearchString(searchString,"1"));
        }
        private void Reset()
        {

            //txtTen.Text = "";

            //txtNgay.Text = "";
            //txtNguoiDang.Text = "";
        }
        protected void btnTim_Click(object sender, EventArgs e)
        {
            

        }

        private void source()
        {
            repTinTuc.DataSource = TinTuc_BLL.LayTatCa();
            repTinTuc.DataBind();
        }

        protected void Unnamed2_SelectedIndexChanged(object sender, EventArgs e)
        {
           
           
        }

        protected void btnSapXep_Click(object sender, EventArgs e)
        {
            if (dlSapXep.SelectedValue == "0")
            {
                repTinTuc.DataSource = TinTuc_BLL.LayTatCa();
                repTinTuc.DataBind();
            }
            else
                if (dlSapXep.SelectedValue == "1")
                {
                    repTinTuc.DataSource = TinTuc_BLL.SapGiam();
                    repTinTuc.DataBind();
                }
        }

       


    }
}